package com.itheima.project.web;

import com.itheima.project.basic.ResponseWrap;
import com.itheima.project.core.enums.trade.TradingEnum;
import com.itheima.project.face.NativePayFace;
import com.itheima.project.utils.ResponseWrapBuild;
import com.itheima.project.vo.trade.RefundRecordVo;
import com.itheima.project.vo.trade.TradingVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName NativePayFace.java
 * @Description Native支付方式Face接口：商户生成二维码，用户扫描支付
 */
@RequestMapping("trade-native")
@RestController
@Api(tags = "Native支付controller")
public class NativePayController {

    @Autowired
    NativePayFace nativePayFace;

    /***
     * @description 统一收单线下交易预创建
     * 收银员通过收银台或商户后台调用此接口，生成二维码后，展示给用户，由用户扫描二维码完成订单支付。
     * @param tradingVo 订单单
     * @return  二维码路径
     */
    @PostMapping("create-down-line-trading")
    @ApiOperation(value = "统一收单线下交易",notes = "统一收单线下交易")
    @ApiImplicitParam(name = "tradingVo",value = "交易单",required = true,dataType = "TradingVo")
    ResponseWrap<TradingVo> createDownLineTrading(@RequestBody TradingVo tradingVo){
        TradingVo tradingVoResult = nativePayFace.createDownLineTrading(tradingVo);
        return ResponseWrapBuild.build(TradingEnum.SUCCEED,tradingVoResult);
    }

    @GetMapping("queryQrCode/{orderNo}")
    @ApiOperation(value = "查看二维码",notes = "查看二维码")
    @ApiImplicitParam(name = "orderNo",value = "查看二维码",dataType = "Long")
    public ResponseWrap<String> queryQrCode(@PathVariable("orderNo") Long orderNo){
        return ResponseWrapBuild.build(TradingEnum.SUCCEED,nativePayFace.queryQrCodeUrl( orderNo));
    }

}
